Use case: HAL CORDIC calculate in polling / zero-overhead mode

Sequence diagram

CORDIC calculation in polling / zero-overhead mode

  @startuml

  participant "User application\n(thread mode)" as appli
  participant "<b>HAL CORDIC</b>" as cordic

  == Initialization / configuration ==
  appli -> cordic : HAL_CORDIC_Init(&hcordic)
  appli -> cordic : HAL_CORDIC_Configure(&hcordic, &cordic_config)

  == Calculation ==
  appli -> cordic : HAL_CORDIC_Calculate(&hcordic, input_data, output_data, n, timeout)\n/ HAL_CORDIC_CalculateZO(...)
  cordic --> appli : HAL status

  @enduml

Code snippet

HAL1

HAL2

#define INPUT_BUFFER_SIZE 4U
#define OUTPUT_BUFFER_SIZE 4U

int32_t input_data[INPUT_BUFFER_SIZE] =  {0x80000000, 0x90000000, 0xA0000000, 0xB0000000};
int32_t output_data[OUTPUT_BUFFER_SIZE] = {0U};










CORDIC_HandleTypeDef hcordic;
CORDIC_ConfigTypeDef cordic_config;

hcordic.Instance = CORDIC;
HAL_CORDIC_Init(&hcordic);



cordic_config.Function         = CORDIC_FUNCTION_SINE;
cordic_config.Precision        = CORDIC_PRECISION_6CYCLES;
cordic_config.Scale            = CORDIC_SCALE_0;
cordic_config.NbWrite          = CORDIC_NBWRITE_1;
cordic_config.NbRead           = CORDIC_NBREAD_1;
cordic_config.InSize           = CORDIC_INSIZE_32BITS;
cordic_config.OutSize          = CORDIC_OUTSIZE_32BITS;

HAL_CORDIC_Configure(&hcordic, &cordic_config)

HAL_CORDIC_Calculate(&hcordic, input_data, output_data, 4, 10);
/* OR */
HAL_CORDIC_CalculateZO(&hcordic, input_data, output_data, 4, 10);
#define INPUT_BUFFER_SIZE 4U
#define OUTPUT_BUFFER_SIZE 4U

int32_t input_data[INPUT_BUFFER_SIZE] =  {0x80000000, 0x90000000, 0xA0000000, 0xB0000000};
int32_t output_data[OUTPUT_BUFFER_SIZE] = {0U};

hal_cordic_buffer_desc_t input_buffer = {
    .p_data = input_data,
    .size_word = INPUT_BUFFER_SIZE};

hal_cordic_buffer_desc_t output_buffer = {
    .p_data = output_data,
    .size_word = OUTPUT_BUFFER_SIZE};

hal_cordic_handle_t hcordic;
hal_cordic_config_t cordic_config;


HAL_CORDIC_Init(&hcordic, HAL_CORDIC);

HAL_RCC_CORDIC_EnableClock();

cordic_config.function   = HAL_CORDIC_FUNCTION_SINE;
cordic_config.precision  = HAL_CORDIC_PRECISION_6_CYCLE;
cordic_config.scaling_factor = HAL_CORDIC_SCALING_FACTOR_0;
cordic_config.nb_args    = HAL_CORDIC_NB_ARG_1;
cordic_config.nb_results = HAL_CORDIC_NB_RESULT_1;
cordic_config.in_width    = HAL_CORDIC_IN_WIDTH_32_BIT;
cordic_config.out_width   = HAL_CORDIC_OUT_WIDTH_32_BIT;

HAL_CORDIC_SetConfig(&hcordic,&cordic_config);

HAL_CORDIC_Calculate(&hcordic, &input_buffer, &output_buffer, 10);
/* OR */
HAL_CORDIC_CalculateZeroOverhead(&hcordic, &input_buffer, &output_buffer, 10);

Key changes

  1. HAL2 uses buffer descriptors (hal_cordic_buffer_desc_t) instead of raw pointers and element counts.

  2. HAL2 updates the API naming and signatures: HAL_CORDIC_Configure() becomes HAL_CORDIC_SetConfig(), and HAL_CORDIC_CalculateZO() becomes HAL_CORDIC_CalculateZeroOverhead().

  3. HAL2 explicitly enables the peripheral clock using HAL_RCC_CORDIC_EnableClock().